package com.cwf.system.vo;

import com.cwf.system.entity.Permission;
import lombok.*;

import java.util.ArrayList;
import java.util.List;


@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class PermissionTreeVO {


    /**
     * 功能id
     */
    private Long id;
    /**
     * 功能名称
     */
    private String title;
    /**
     * 级别
     */
    private Integer rank;
    /**
     * 功能父级id
     */
    private Long parentId;
    /**
     * 路径
     */
    private String path;
    /**
     * 名称
     */
    private String name;
    /**
     * 组件地址
     */
    private String component;
    /**
     * 重定向
     */
    private String redirect;
    /**
     * 元标签
     */
    private String meta;
    /**
     * 功能状态
     */
    private Integer state;
    /**
     * 标记
     */
    private String mark;
    /**
     * 分类(1是菜单2是按钮)
     */
    private Integer category;
    /**
     * 图标地址
     */
    private String icon;

    /**
     * 是否显示
     */
    private Integer isShow;

    private Boolean is = true;


    List<PermissionTreeVO> children = new ArrayList<>();


    public static PermissionTreeVO voTovo(PermissionTreeVO permissionTreeVO){

        PermissionTreeVO permissionTreeVO1 = new PermissionTreeVO();
        permissionTreeVO1.setId(permissionTreeVO.getId());
        permissionTreeVO1.setRank(permissionTreeVO.getRank());
        permissionTreeVO1.setParentId(permissionTreeVO.getParentId());

        permissionTreeVO1.setChildren(permissionTreeVO.getChildren());

        return permissionTreeVO1;

    }



    public static PermissionTreeVO toVo(Permission permission){
        PermissionTreeVO permissionTreeVO = new PermissionTreeVO();

        permissionTreeVO.setId(permission.getId());
        permissionTreeVO.setTitle(permission.getTitle());
        permissionTreeVO.setRank(permission.getRank());
        permissionTreeVO.setParentId(permission.getParentId());
        permissionTreeVO.setPath(permission.getPath());
        permissionTreeVO.setName(permission.getName());
        permissionTreeVO.setComponent(permission.getComponent());
        permissionTreeVO.setRedirect(permission.getRedirect());
        permissionTreeVO.setMeta(permission.getMeta());
        permissionTreeVO.setState(permission.getState());
        permissionTreeVO.setMark(permission.getMark());
        permissionTreeVO.setCategory(permission.getCategory());
        permissionTreeVO.setIcon(permission.getIcon());
        permissionTreeVO.setIsShow(permission.getIsShow());
        permissionTreeVO.setIs(true);



        return permissionTreeVO;
    }


    public static List<PermissionTreeVO> toVOList(List<Permission> list){

        List<PermissionTreeVO> permissionTreeVOList = new ArrayList<>();
        for (Permission permission : list){
           permissionTreeVOList.add(toVo(permission));
        }
        return permissionTreeVOList;
    }




}
